package webapp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ioc.IocFactory;
import com.ioc.IocFactoryInstance;
import ejw.RestfulHandler;

/**
 * restful Servlet基类
 * @author tiger
 *
 */
public class BaseHandler extends RestfulHandler {
	/** 系统注入工厂类 */
	public static IocFactory<?> ioc = IocFactoryInstance.getFactoryInstance();
	
	/**
	 * 设置Attribute
	 * @param name
	 * @param object
	 */
	public void setAttribute(String name,Object object){
		this.getServerInterface().setAttribute(name, object);
	}
	
	/**
	 * 获取request
	 */
	public HttpServletRequest request(){
		return this.getServerInterface().getServletRequest();
	}
	
	/**
	 * 取Attribute
	 * @param attrName
	 * @return
	 */
	public Object getAttribute(String attrName){
		return this.getServerInterface().getAttribute(attrName);
	}
	
	/**
	 * 取Parameter
	 * @param param
	 * @return
	 */
	public String getParameter(String param){
		return this.getServerInterface().getServletRequest().getParameter(param);
	}
	
	/**
	 * 获取response
	 * @return
	 */
	public HttpServletResponse response(){
		return this.getServerInterface().getServletResponse();
	}
	
	/**
	 * 根据name取得一个session对象
	 * @param name
	 * @return
	 */
	public Object setSession(String name){
		return this.getServerInterface().getServletRequest().getSession().getAttribute(name);
	}
	
	/**
	 * 设置一个session对象
	 * @param name
	 * @param value
	 */
	public void setSession(String name ,Object value){
		this.getServerInterface().getServletRequest().getSession().setAttribute(name, value);
	}
	
	/**
	 * 移除session对象
	 * @param name
	 */
	public void removeSession(String name){
		this.getServerInterface().getServletRequest().getSession().removeAttribute(name);
	}
}
